import { OrganizationInfo } from './Organization';

/**
 * 请求数据权限规则相关信息入参
 */
export interface GetDataPermissionRuleParams {
  pageNo: number;
  pageSize: number;
  ruleName?: string;
  companyId?: number;
}

/**
 * 数据权限规则信息
 */
export interface DataPermissionRuleInfo {
  ruleId: number;
  ruleName: string;
  overallSituation: number;
  resourceNames: string[];
  ruleContent: string;
}

/**
 * 数据权限规则详情信息
 */
export interface DataPermissionRuleDetailInfo {
  ruleId: number;
  ruleName: string;
  ruleTypeKey: string;
  overallSituation: number;
  resourceKeys: string[];
  hasChildren?: boolean;
  organizations?: {
    organizationId: number;
    organizationName: string;
  }[];
  users?: {
    userId: number;
    userName: string;
  }[];
  ruleParams?: RuleParamsForQuery[];
}

export interface RuleParamsForQuery {
  fieldName: string;
  fieldKey: string;
  decisionSymbolName: string;
  decisionSymbolKey: string;
  fieldValue: string;
  relationSymbol: string;
}

/**
 * 新建数据权限股则入参
 */
export interface AddDataPermissionRuleParams {
  ruleName: string;
  ruleTypeKey: string;
  overallSituation?: number;
  resourceKeys: string[];
  organizationIds?: number[];
  hasChildren?: boolean;
  userIds?: number[];
  ruleParams?: RuleParams[];
}

/**
 * 修改数据权限规则入参
 */
// export interface ModifyDataPermissionRuleParams {
//   ruleName: string;
//   ruleTypeKey: string;
//   overallSituation: number;
//   resourceKeys: string[];
//   organizationIds?: number[];
//   hasChildren?: boolean;
//   userIds?: number[];
//   ruleParams?: RuleParams[];
// }

export interface RuleParams {
  fieldKey: string | null;
  decisionSymbolKey: string | null;
  fieldValue: string | null;
  relationSymbol: string | null;
}

/**
 * 数据权限数据源信息
 */
export interface DataPermissionResource {
  resourceKey: string;
  resourceName: string;
}

/**数据权限规则类型信息 */
export interface DataPermissionRuleType {
  typeKey: string;
  typeName: string;
}

/**数据权限数据源属性信息 */
export interface DataPermissionField {
  fieldKey: string;
  fieldName: string;
}

/**数据权限数据源属性支持的判定符信息 */
export interface DataPermissionFieldDecisionSymbol {
  decisionSymbolKey: string;
  decisionSymbolName: string;
}

/**数据权限规则关联用户信息 */
export interface DataPermissionRuleUser {
  userId: number;
  nickName: string;
  userName: string;
  organizationName: string;
  createTime: string;
}

/**数据权限规则关联角色信息 */
export interface DataPermissionRuleRole {
  roleId: number;
  roleName: string;
  createTime: string;
}

/**分配用户数据权限参数 */
export interface AddDataPermissionRuleDistributionParams {
  ruleId: number;
  allocationType: string;
  allocationValues: number[];
}

/**取消用户数据权限参数 */
export interface DelDataPermissionRuleDistributionParams {
  ruleId: number;
  allocationType: string;
  allocationValues: number[];
}

export interface GetDataPermissionParams {
  pageNo: number;
  pageSize: number;
  ruleName: string;
  companyId: number;
}

/**查询已分配用户数据参数 */
export interface GetDataPermissionRuleUserParams {
  pageNo: number;
  pageSize: number;
}

export interface GetDataPermissionUserRules {
  ruleId: number;
  ruleName: string;
  overallSituation: number;
  resourceNames: string[];
  ruleContent: string;
}

/**
 * 数据权限信息
 */
export interface DataPermissionInfo {
  tables: {
    tableId: number;
    hmTableName: string;
  }[];
  users: {
    userId: number;
    userName: string;
  }[];
  roles: {
    roleId: number;
    roleName: string;
  }[];
  dataPermissionGroupId: number;
  organization: OrganizationInfo;
  property: string;
  propertyValue: string;
  empowermentUserName: string;
}

export interface DelDataPermissionRuleParam {
  isSafeDelete: boolean;
}

/**
 * 新建数据权限入参
 */
export interface AddDataPermissionParams {
  propertyType: 'user_id' | 'role_id' | 'organization_id';
  propertyValue: number;
  tableIds: string;
  userIds?: number[];
  organizationId?: number;
  roleIds?: number[];
  empowermentUserName: string;
}

/**
 * 修改数据权限入参
 */
export interface ModifyDataPermissionParams {
  propertyType: 'user_id' | 'role_id' | 'organization_id';
  propertyValue: number;
  tableIds: string;
  userIds?: number[];
  organizationId?: number;
  roleIds?: number[];
}

/**
 * 获取数据表入参
 */
export interface GetTableParams {
  pageNo: number;
  pageSize: number;
  hmTableName: string;
}

/**
 * 获取被授权者的参数
 */
export interface GetAuthorizerParams {
  pageNo: number;
  pageSize: number;
  keyWord: string;
}

/**
 * 权限被授权范围
 */
export interface GetAuthorizerResponse {
  userId: number;
  userName: number;
  roleId: number;
  roleName: string;
  companyId: number;
  companyName: string;
}
